<?php
/**
 * @file
 * Retreives all 'GET' parameters from the request and stores them in a
 * JavaScript variable.
 *
 * The application can then explicitly pass these parameters as GET (or POST)
 * parameters through hyperlinks or AJAX calls. This mechanism is required for
 * the following reasons:
 * o Facebook
 *   - Facebook sends 'fb_sig_xxx' parameters to only the main canvas page.
 *     Hyperlinks or AJAX calls do not automatically forward these parameters
 *     => the requested page(s) will not have access to the user's Facebook
 *     data.
 *   - If the application uses Facebook's 'Automatic Authentication' APIs, it
 *     does not have a Facebook 'Session' and thus cannot retreive the user's
 *     Facebook data from a session.
 *   - The user's Facebook data cannot be stored in PHP Session Variables
 *     because PHP Sessions require the use of cookies. Under Facebook's
 *     'iframe' architecture, the application is served from a 3rd-party domain. 
 *     Most modern browsers do not allow 3rd-party cookies by default. Using P3P
 *     headers does not solve the problem completely because Safari (up until
 *     v4.0) does not support P3P.
 *
 * Usage:
 *  - The main canvas page should include/require this page once and only once
 *    within its '<head></head>' tags.
 *  - Hyperlinks or AJAX calls to pages that need the data passed through the
 *    'GET' request must forward the retreived parameters.
 *
 * Parameter(s):
 *  - $PATH_COMMON : Relative path from the calling page to the 'common'
 *                   directory (e.g. '../common/').
 *
 * Global variable(s) set:
 *  - None.
 *
 * Global variable(s) unset:
 *  - None.
 *
 * Global JavaScript variable(s) set:
 *  - {JS_VAR_PARAMS_GET} : The retreived parameters.
 *                          (E.g. "key1=value1&key2=value2&key3=value3")
 *
 * Exception(s):
 *  - None.
 *
 * This file includes/requires:
 *  - h_js_common.php
 */

// header file(s) ==============================================================
require_once $PATH_COMMON . "php/h_js_common.php";


// implementation ==============================================================
// retreive all get parameters
$params_get = "";
foreach ($_GET as $key => $value) {
  $params_get .= "&" . $key . "=" . $value;
}
// remove first '&'
$params_get = substr($params_get, 1);
?>
<script type="text/javascript">
var <?php echo JS_VAR_PARAMS_GET ?> = "<?php echo $params_get ?>";
</script>
